<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp" %>
<title>添加地址信息</title>
</head>
<body>
<fieldset class="layui-elem-field" style="margin:30px;padding:30px">
	<legend>添加地址</legend>
	<div class="layui-field-box">
			<form class="layui-form-pane layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label">用户账号</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="userCode" type="text" placeholder="请输入用户账号"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">收件人名称</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="name" type="text" placeholder="请输入收件人名称"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">收件人电话</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="tel" type="text" placeholder="请输入收件人电话"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				<div class="layui-form-item">
				<label class="layui-form-label">省：</label>
					<div class="layui-input-inline">
						<select name="addr1" lay-verify="required" lay-search lay-filter="addr1"></select>
					</div>
				</div>
				
				<div class="layui-form-item">
				<label class="layui-form-label">市：</label>
					<div class="layui-input-inline">
						<select name="addr2" lay-verify="required" lay-search lay-filter="addr2"></select>
					</div>
				</div>
				
				<div class="layui-form-item">
				<label class="layui-form-label">区：</label>
					<div class="layui-input-inline">
						<select name="addr3" lay-verify="required" lay-search></select>
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">详细地址</label>
					<div class="layui-input-inline">
						<input class="layui-input" name="addr4" type="text" placeholder="请输入详细地址"
						required lay-verify="required" autocomplete="off">
					</div>
				</div>
				
				
				<div class="layui-form-item">
					<div class="layui-input-inline">
						<input type="button" value="确定" class="layui-btn" lay-submit lay-filter="add"  />
						<input type="reset" value="重置" class="layui-btn layui-btn-primary" />
					</div>
				</div>
			</form>
		</div>
		
	</fieldset>
	
	<script type="text/javascript">
	
	getSelect('addr1',"000000");
	function getSelect(selectid,parentCode){
		if(parentCode==""){
			$("select[name^='addr']").empty();
			form.render("select");
			return;
		}
		ajax({parentCode:parentCode},'/addrtol/get.do','json',function(data){
			var html = "<option value=''>-- 请选择 --</option>";
			$.each(data,function(i,dom){
				html += "<option value='"+ dom.code +"'>"+ dom.name +"</option>"
			});
			$("select[name='"+ selectid +"']").html(html);

			form.render('select');
		})
	}
	formsele('addr1','addr2');
	formsele('addr2','addr3');
	function formsele(filter,selectid){
		form.on("select(" + filter + ")",function(data){
			getSelect(selectid,data.value);
		})
	}
		
	formOn('submit(add)','/address/insert.do','text',function(data){	
		if(data=="A"){	
			layer.msg("该用户不存在");	
		}else if(data=="D"){
			layer.msg("添加失败");
		}else{
			layer.msg("添加成功",toClose);		
		}
	})
	</script>	

</body>
</html>